package com.Lgwd.controller.backinfoController;


import com.Lgwd.dao.BackDao;
import com.Lgwd.entity.BackInfoEntity;
import com.Lgwd.entity.UserEntiy;
import com.Lgwd.entity.UserItemInfoEntity;
import com.Lgwd.service.backService.BackInfoService;
import com.Lgwd.utils.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 背包系统
 */
@Slf4j
@RestController
@CrossOrigin
public class BackInfoController {


    @Autowired
    BackInfoService backInfoService;
    /**
     * 查询背包内所有物品 同步到页面
     */

    @RequestMapping("/getBackItem")
    public ResponseData getBackItem(@RequestBody BackDao backDao){
        List<BackInfoEntity> backInfoEntities=backInfoService.findAllByUserAccountAndFlag(backDao);
        if(backInfoEntities==null){
            return ResponseData.defaultFail("还未获得任何物品");
        }
        return ResponseData.defaultSuccess(backInfoEntities);
    }



    /**
     * 穿戴装备接口
     */
    @RequestMapping("/itemUpOrDown")
    public ResponseData itemUpOrDown(@RequestBody BackDao backDao){
        log.info("接受到的装备信息为："+backDao);
        UserEntiy userEntiy= backInfoService.updateUserPropertyAndUseItem(backDao);
        return ResponseData.defaultSuccess(userEntiy);
    }


    /**
     * 穿戴装备接口
     */
    @RequestMapping("/itemDown")
    public ResponseData UpOr(@RequestBody BackDao backDao){
        log.info("接受到的卸下装备信息为："+backDao);
        UserEntiy userEntiy= backInfoService.updateUserItemDown(backDao);
        return ResponseData.defaultSuccess(userEntiy);
    }

    /**
     * 删除背包物品
     */

    @RequestMapping("/deleteItem")
    public ResponseData deleteItem(@RequestBody BackDao backDao){
        List<BackInfoEntity> backInfoEntities=backInfoService.deleteItem(backDao);

        return ResponseData.defaultSuccess(backInfoEntities);
    }

}
